<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
echo "<response>";
session_start();
if ($_SESSION['kteam_auth'] != true)
{
    $expire=time()+60*60;
    setcookie("redirector", "ticket.html", $expire);
    echo "<result>Login</result>";
    echo "</response>";
    header("Location: login.html");
    exit;
}

include("sqlconnect.php");
include("sqlgenerator.php");
$debug = true;

$fields[0] = $_GET['ticket_rate'];
$fields[1] = $_GET['coupon_value'];
$fields[2] = $_GET['l0'];
$fields[3] = $_GET['l1'];
$fields[4] = $_GET['l2'];

db_connect();

// Query the ticketinfo ID from the ticket rate
$query = get_ticketinfo($fields[0]);
if ($debug) {
    echo '<debug>';
    echo 'Query: ' . $query;
    echo '</debug>';
}
$result = db_query($query);
if ($debug) {
    echo '<debug>';
    echo 'Query Result: ' . $result;
    echo '</debug>';
}

if (mysql_num_rows($result)!=0) {
    $row = mysql_fetch_array($result);
    $query = update_ticketinfo($row['id'], $fields);
    if ($debug) {
        echo '<debug>';
        echo 'Query: ' . $query;
        echo '</debug>';
    }
    $result = db_query($query);
    if ($debug) {
        echo '<debug>';
        echo 'Query Result: ' . $result;
        echo '</debug>';
    }
    echo "<result>Updated</result>";
} else {
    $query = insert_ticketinfo($fields);
    if ($debug) {
        echo '<debug>';
        echo 'Query: ' . $query;
        echo '</debug>';
    }
    $result = db_query($query);
    if ($debug) {
        echo '<debug>';
        echo 'Query Result: ' . $result;
        echo '</debug>';
    }
    echo "<result>Added</result>";
}
echo "</response>";
#header("Location: producer_create.html");
?>